package com.soccertgc.data.filters
{
	public class DataFilter
	{
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		protected var _name:String;
		protected var _field:String;
		protected var _value:Object;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------	
		
		public function DataFilter(name:String, field:String, value:Object):void
		{
			_name  = name;
			_field = field;
			_value = value;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------

		public function get name():String
		{
			return _name;
		}

		public function get field():String
		{
			return _field;
		}

		public function get value():Object
		{
			return _value;
		}

		public function set value(value:Object):void
		{
			_value = value;
		}

		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Evaluate the filter using the given object 
		 * @param obj Object to evaluate with the filter
		 * @return True if the given object is not null, has a the 'field' and the 'field' is
		 * strict equal to 'value'
		 */		
		public function evaluate(obj:Object):Boolean
		{
			return 	obj != null &&
					obj.hasOwnProperty(_field) &&
					obj[_field] === value;
		}

	}
}